package service;

import robot.RobotAgent;
import com.agentfactory.logic.agent.Actuator;
import com.agentfactory.logic.lang.FOS;

public class TurnRadarActuator extends Actuator {
	@Override
	public boolean act(FOS action) {
		
        String direction = action.argAt(0).toString();
        int angle = 0;
        if (action.numArguments() == 2) {
            angle = Integer.parseInt(action.argAt(1).toString());
        }
		
		RobotAgentService robotAgentService = (RobotAgentService)this.getService(ServiceConstants.SERVICE_NAME);
        if (robotAgentService == null) {
            return false;
        }
		RobotAgent robot = robotAgentService.lookupRobotAgent(this.agent.getName());
		
        if (direction.equals("left")) {
        	robot.radarAngle = angle;
        } else if (direction.equals("right")) {
        	robot.radarAngle = - angle;
        } else {
            return false;
        }
        return true;
	}
}
